package com.situ.wms.dao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.situ.wms.entity.GoodsNotes;
import com.situ.wms.util.DBUtil;

public class GoodsNotesDao {
	public List<GoodsNotes> selectByname(int page, int limit,String keyword){ 
		
		String sql;
		if(keyword==null||keyword.equals("")) {
			System.out.println(22222);
		sql="select * from goodsnotes  limit ? ,? ";}
		else {
			sql="select * from goodsnotes where instr(goodsname,'"+keyword+"')>0 limit ? , ? ";
		}
		return DBUtil.executeDQL(sql, GoodsNotes.class,(page-1)*limit ,limit);
	}
	
	
	//商品入库记录
	public void notesIn(GoodsNotes goodsnotes) {
		String sql="insert into goodsnotes (goodsname,goodsfactory,goodsmodel,goodssize,goodsnumber,actiondate,actionpart,chargeman,status) values(?,?,?,?,?,?,?,?,?) ";
		String goodsname=goodsnotes.getGoodsname();
		String goodsfactory=goodsnotes.getGoodsfactory();
		String goodsmodel=goodsnotes.getGoodsmodel();
		String goodssize=goodsnotes.getGoodssize();
		int goodsnumber=goodsnotes.getGoodsnumber();
		Date actiondate=goodsnotes.getActiondate();
		String actionpart=goodsnotes.getActionpart();
		String chargeman=goodsnotes.getChargeman();
		String status=goodsnotes.getStatus();
		DBUtil.executeDML(sql,goodsname,goodsfactory,goodsmodel,goodssize,goodsnumber,actiondate,actionpart,chargeman,status);
	}

	//商品出库记录
	public void notesOut(GoodsNotes goodsnotes) {
		String sql="insert into goodsnotes (goodsname,goodsfactory,goodsmodel,goodssize,goodsnumber,actiondate,actionpart,chargeman,status) values(?,?,?,?,?,?,?,?,?) ";
		String goodsname=goodsnotes.getGoodsname();
		String goodsfactory=goodsnotes.getGoodsfactory();
		String goodsmodel=goodsnotes.getGoodsmodel();
		String goodssize=goodsnotes.getGoodssize();
		int goodsnumber=goodsnotes.getGoodsnumber();
		Date actiondate=goodsnotes.getActiondate();
		String actionpart=goodsnotes.getActionpart();
		String chargeman=goodsnotes.getChargeman();
		String status=goodsnotes.getStatus();
		DBUtil.executeDML(sql,goodsname,goodsfactory,goodsmodel,goodssize,goodsnumber,actiondate,actionpart,chargeman,status);
	}
	
	public Long count( String keyword) {
		String sql;
		if(keyword==null||keyword.equals("")) {
			sql="select count(1) from goodsNotes";
			}
			else {
				
				sql="select count(1) from goodsnotes where instr(goodsname,'"+keyword+"')>0 ";
			}
		
		return DBUtil.executeCount(sql);
	}

	public List<GoodsNotes> selectBytime(int page, int limit,String keyword) {
		String sql;
		SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
		Date date =new Date();
		try {
			date=sdf.parse(keyword);
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(keyword==null||keyword.equals("")) {

		sql="select * from goodsnotes  limit ? ,? ";}
		else {
			sql="select * from goodsnotes where actiondate = ? limit ? ,?";
		}
		 
		return DBUtil.executeDQL(sql,GoodsNotes.class, date,(page-1)*limit ,limit);
	}


	public Long countByDate(String keyword) {
		SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
		Date date =new Date();
		String sql;
		try {
			date=sdf.parse(keyword);
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(keyword==null||keyword.equals("")) {
			sql="select count(1) from goodsNotes";
			}
			else {
				
				sql="select count(1) from goodsnotes where actiondate = ? ";
			}
		
		return DBUtil.executeCount(sql,date);
	}


	public void update(GoodsNotes goodsnote) {
		// TODO Auto-generated method stub
		
		String sql ="update goodsnotes set goodsname =? , goodsfactory=? , goodsmodel=? , goodssize=? , goodsnumber=?, actiondate=?, actionpart=?, chargeman=?, status=? where id =?";
	 	DBUtil.executeDML(sql,goodsnote.getGoodsname(),goodsnote.getGoodsfactory(),goodsnote.getGoodsmodel(),goodsnote.getGoodssize(),goodsnote.getGoodsnumber(),goodsnote.getActiondate(),goodsnote.getActionpart(), goodsnote.getChargeman(),goodsnote.getStatus(),goodsnote.getId());
	}
}
